package org.kymjs.emoji.model;

import java.util.ArrayList;
import java.util.List;

import org.kymjs.emoji.R;

/**
 * Emoji在手机上的显示规则
 * 
 * @author kymjs
 */
public enum DisplayRules {
    // 注意：value不能从0开始，因为0会被库自动设置为删除按钮
    KJEMOJI1(1, 1, R.drawable.ic_launcher, "hello1:"),

    KJEMOJI2(1, 2, R.drawable.ic_launcher, "hello2:"),

    KJEMOJI3(1, 3, R.drawable.ic_launcher, "hello3:"),

    KJEMOJI4(1, 4, R.drawable.ic_launcher, "hello4:"),

    KJEMOJI5(1, 5, R.drawable.ic_launcher, "hello5:"),

    KJEMOJI6(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI7(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI8(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI9(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI10(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI11(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI12(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI13(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI14(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI15(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI16(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJ17(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJ18(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJ19(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI20(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI21(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI22(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI23(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI24(1, 6, R.drawable.ic_launcher, "hello6:"),

    KJEMOJI25(1, 6, R.drawable.ic_launcher, "hello6:");

    /********************************* 操作 **************************************/
    private String emojiStr;
    private int value;
    private int resId;
    private int type;

    private DisplayRules(int type, int value, int resId, String cls) {
        this.type = type;
        this.emojiStr = cls;
        this.value = value;
        this.resId = resId;
    }

    public String getEmojiStr() {
        return emojiStr;
    }

    public int getValue() {
        return value;
    }

    public int getResId() {
        return resId;
    }

    public int getType() {
        return type;
    }

    private static EmojiIcon getEmojiFromEnum(DisplayRules data) {
        return new EmojiIcon(data.getResId(), data.getValue(),
                data.getEmojiStr());
    }

    public static EmojiIcon getEmojiFromRes(int resId) {
        for (DisplayRules data : values()) {
            if (data.getResId() == resId) {
                return getEmojiFromEnum(data);
            }
        }
        return null;
    }

    public static EmojiIcon getEmojiFromValue(int value) {
        for (DisplayRules data : values()) {
            if (data.getValue() == value) {
                return getEmojiFromEnum(data);
            }
        }
        return null;
    }

    public static EmojiIcon getEmojiFromName(String emojiStr) {
        for (DisplayRules data : values()) {
            if (data.getEmojiStr().equals(emojiStr)) {
                return getEmojiFromEnum(data);
            }
        }
        return null;
    }

    public static List<EmojiIcon> getAllByType(int type) {
        List<EmojiIcon> datas = new ArrayList<EmojiIcon>(values().length);
        for (DisplayRules data : values()) {
            if (data.getType() == type) {
                datas.add(getEmojiFromEnum(data));
            }
        }
        return datas;
    }
}
